import { defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';
import {resolve} from 'path';
import {CWD_PATH} from './src/config';


const resolveApp = (...paths) => resolve(CWD_PATH, ...paths);
const ENTRY = resolveApp('./src/index.ts');
const OUT_DIR = resolve('./dist');


export default defineConfig({
    resolve: {
        extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.ejs'],
        alias: [
            {find: /^@\/(.*)$/, replacement: resolve(__dirname, './src/$1')}
        ]
    },
    build: {
        lib: {
            entry: ENTRY,
            formats: ['es'],
            name: 'kit-cli',
            fileName: '[name].js',
        },
        outDir: OUT_DIR,
        rollupOptions: {
            // external: /template/
        },
    },
    plugins: [
        ...VitePluginNode({
            appPath: ENTRY
        })
    ]
});
